package juc;

import java.util.concurrent.CompletableFuture;

public class CompletableFutureDemo {
    public static void main(String args[]) throws Exception{
//        CompletableFuture<Void> completableFuture = CompletableFuture.runAsync(() -> {
//            System.out.println(Thread.currentThread().getName() + "\t没返回");
//        });
//        completableFuture.get();

        //异步回调
        CompletableFuture<Integer> integerCompletableFuture = CompletableFuture.supplyAsync(() -> {
            System.out.println("sss");
            int age = 10/0;
            return 1024;
        });

        integerCompletableFuture.whenComplete((t,u) -> {
           System.out.println("****t\t" + t);
           System.out.println("****u\t" + u);
        }).exceptionally(f -> {
           System.out.println(f.getMessage());
           return 4444;
        }).get();

    }
}
